Skip to content

fix(land): prove push access only on E/F, and fence F's push on the land ref - #695

Merged
khaliqgant merged 6 commits into
mainfrom
fix/land-preflight-write-stages
Nov 3, 2026
Merged

khaliqgant merged 6 commits into
mainfrom
fix/land-preflight-write-stages

Conversation

@khaliqgant

@khaliqgant khaliqgant commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Companion to cloud#5944, which fixes S1 on Cloud merge train #5941: an auto run's contents:write grant now goes to stages E (the gate's snapshot branch) and F (the squash to the base) only. A–D, where an agent reviews and fixes untrusted change content, run on a read grant.

land.flow.ts dry-ran a push on every auto stage, so with that grant every auto run would stop needs_human at A-adversarial.

  • The push dry-run now runs only when input.stage is in WRITE_STAGES (E, F). The gh auth status check stays on every auto stage (a read grant authenticates gh too).
  • The refusal names the stage: needs a push-capable git credential at stage E.

Tests

  • auto: review and fix stages run on a read-only credential; a push-denied credential stops at E before any push (replaces the old "fails preflight before any stage runs").
  • auto: the push dry-run runs only on stages E and F.
  • Mutation check: with the stage condition removed, both fail.

examples/land: npm test 91/91, npm run typecheck clean. Land-only; nothing in packages/ changes, so no release is needed. The land deployment is redeployed from the merge commit.

Fence stage F's push on the land ref

Answers the cloud#5944 review (Devin, Codex, Greptile, kjgbot) that a cancelled stage F can outlive its cancellation: Cloud writes cancelled before teardown, a provider stop failure can still return 200, and RelayAuth revocation does not revoke the GitHub credential inside the sandbox.

Superseding a land run means a newer push to its land ref. F now pushes git push --atomic --force-with-lease=refs/heads/<ref>:<pinnedSha> origin <squash>:refs/heads/<base> <pinnedSha>:refs/heads/<ref>. If the ref moved, GitHub rejects the lease and the atomic push lands nothing on the base, whatever the old sandbox still holds. The run then re-reads the ref and ends cancelled (superseded) instead of retrying through D.

Test: auto: F fences its push on the land ref, and a superseded run lands nothing (fails with the fence removed). examples/land: 92/92, typecheck clean.

🤖 Generated with Claude Code


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.


Summary by cubic

Fixes the land auto preflight and fences stage F's push so read-only review stages work and a superseded run can never land stale work.

Cloud now grants contents:write only to auto stages E (gate snapshot branch) and F (squash to base); stages A–D run on a read grant. The preflight previously dry-ran a push on every auto stage, so every auto run would stop at A-adversarial. Separately, stage F's push was unsafe: a cancelled run's sandbox can outlive the cancel and still hold its credential, so it could land after being superseded.

  • The push dry-run now runs only on WRITE_STAGES (E, F); the gh auth status check stays on every auto stage.
  • Stage F pushes atomically with --force-with-lease on the land ref, deleting the ref in the same transaction (pushing it to its own value would be dropped as up to date and check nothing), and ends the run cancelled as superseded if the ref moved instead of retrying through D.
  • If the push fails only on the client (GitHub accepted it but the connection dropped), F fetches the base and records the landed commit before considering supersession.
  • A replayed F that finds its own Land-Run trailer on the base reconciles as landed even though its land ref is gone or recreated by a newer submission.
  • The write grant must allow deleting land/* branches; a dry-run push cannot prove branch rules, so this is documented rather than preflighted.
  • The refusal message now names the stage, e.g. needs a push-capable git credential at stage E.

Tests

  • New tests assert the push dry-run runs only on E and F, that A–D (including a fix round) proceed on a read-only credential, and that a moved land ref cancels F without landing anything.
  • Additional tests cover a push that landed but failed on the client, and replayed Fs reconciling as landed with the ref gone or recreated.
  • examples/land/evidence/push-fence provides real-Git evidence that the delete-based fence blocks a moved land ref where the previous lease did not, and captures the server's ref updates on every trial.

Written for commit bd2e03b. Summary will update on new commits.

View guided diff Turn on auto-fix


Agent Relay sessions

  • codex session 01a19dbc · contributor · ran gh pr commands · last active 2026-11-03

Cloud now gives an auto run's write grant to stages E and F only (cloud#5944,
S1 on train #5941): A-D, where an agent reviews and fixes untrusted change
content, run on a read grant. The auto preflight dry-ran a push on every
stage, so every auto run would have stopped needs_human at A-adversarial.
The push dry-run now runs only on E and F (WRITE_STAGES); the gh auth check
stays on every auto stage.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-03T06:53:23.649074Z 7dfb9fb PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 39 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5b1437f7-971b-4794-a7dd-e858fdb9fe4b
Commits

Reviewing files that changed from the base of the PR and between 7dfb9fb and bd2e03b.

Files selected for processing: 6
  • examples/land/README.md
  • examples/land/evidence/push-fence/README.md
  • examples/land/evidence/push-fence/fence-race.py
  • examples/land/evidence/push-fence/output.txt
  • examples/land/land.flow.ts
  • examples/land/tests/flow.test.ts

No actionable comments were generated in the recent review.

Walkthrough

Auto-mode preflight continues to check GitHub authentication at every stage. It checks for push-capable Git credentials only at stages E and F, and reports the stage when that check fails. Tests cover read-only credentials during earlier stages and failed or successful push dry-runs.

Changes: Auto-mode push preflight

Layer / File(s) Summary
Stage-specific credential checks
examples/land/land.flow.ts, examples/land/tests/flow.test.ts
The flow defines stages E and F as write stages and limits push dry-runs and credential checks to those stages. Tests cover earlier stages with read-only credentials, a failed E-stage dry-run ending in needs_human, and successful dry-runs only at E and F.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related PRs

Suggested reviewers: kjgbot

Merge Risk: Minimal · previous review 7dfb9

Auto runs no longer stop at the first review stage when they have only read access. Stages E and F, which push, must still prove they have a push-capable credential, and a failure now names the stage. No other behavior changes, and the change is ready to merge.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Title check Passed The title clearly identifies the main changes: stage-specific push-access checks and fencing stage F's push on the land ref.
Description check Passed The description directly explains the preflight change, stage F push fencing, security rationale, tests, and validation results.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 2 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
Generate docstrings
  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit checks the gates in turn,
At E and F, the push lights burn.
Earlier stages pass with read-only keys,
A failed dry-run pauses with ease.
Tests trace the stages, neat and clear,
Then hops away with carrots near.

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.
Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7b0a17b3-b603-433b-8104-f8d3e7b811d4
Commits

Reviewing files that changed from the base of the PR and between d3668b3 and 7dfb9fb.

Files selected for processing: 2
  • examples/land/land.flow.ts
  • examples/land/tests/flow.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 2 files

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread examples/land/tests/flow.test.ts Resolved
Comment thread examples/land/land.flow.ts Resolved
@greptile-apps

greptile-apps Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 4/5

[High impact] The changes affect auto land runs that review and write to repository branches.

The PR still needs to keep a failed recovery fetch from marking landed work as cancelled.

Summary

Limits push-access checks to stages E and F, and makes F push the squash together with a leased deletion of the land ref.

  • Review and fix stages run without push access.
  • Stage F lands the squash only while its land ref stays pinned.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Stage F atomic push] --> B{Client reports success?}
  B -->|Yes| C[Save landed]
  B -->|No| D[Fetch base and check Land-Run]
  D --> E{Matching commit found?}
  E -->|Yes| C
  E -->|No| F[Check land ref]
  F --> G{Ref moved or deleted?}
  G -->|Yes| H[Save cancelled]
  G -->|No| I[Retry through D or request human help]
Loading

Reviews (4) · Last reviewed commit: "fix(land): reconcile a recreated land re..." · Reviewed by Greptile

Comment thread examples/land/tests/flow.test.ts Resolved
Superseding a land run means a newer push to its land ref. Stage F now
pushes the squash atomically with a --force-with-lease that the land ref
still points at the pinned head, so if the ref moved GitHub rejects the
lease and nothing lands on the base. The run then ends cancelled as
superseded instead of retrying through D.

This is the write fence Cloud's cancellation cannot give on its own
(cloud#5944 review): a cancelled stage's sandbox may outlive the cancel and
still hold its GitHub credential, but it can no longer land.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@khaliqgant khaliqgant changed the title fix(land): prove push access only on the stages that push fix(land): prove push access only on E/F, and fence F's push on the land ref Nov 3, 2026
@kjgbot

kjgbot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Closing duplicate #696 in favor of this PR. The relay handoff arrived after it opened. Keeping gh auth status on all auto stages is compatible with read-only grants; the essential change is limiting the push dry-run to E/F.

Additional fixture coverage available in #696 at 20ae8125: it drives a real C fix round and D with pushDryRunFails: true, proves no push probe in those stages, then refuses at E. The source-only guard and all 91 local tests passed with captured command/output in examples/land/evidence/staged-write-preflight. That is local fixture evidence, not a hosted grant proof.

Comment thread examples/land/land.flow.ts Resolved

@kjgbot kjgbot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read-only review of the added stage-F cancellation fence at exact head a158624. The E/F preflight change covers duplicate #696, which is closed. The new fence has a real-Git race shown inline.

Comment thread examples/land/land.flow.ts Resolved

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 2 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread examples/land/land.flow.ts Resolved
Comment thread examples/land/land.flow.ts Resolved
khaliqgant and others added 2 commits November 2, 2026 23:04
The #695 review (kjgbot, Greptile) showed the no-op fence checks nothing:
pushing the land ref to its own value is dropped from Git's transaction as
up to date, so --force-with-lease only compared the client's advertisement
and a land ref moved mid-push still let the old squash land.

F now deletes the land ref in the same atomic push, leased on the pinned
head. A delete is a real update with an old value, checked inside the
transaction, so if the ref moved the push fails and nothing lands. A replayed
F that finds its own Land-Run trailer on the base reconciles as landed even
though its land ref is gone. Real-Git evidence: examples/land/evidence/push-fence.

Also: the read-only test covers a fix round (C-1) explicitly, and the gh
preflight message no longer claims a write grant.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread examples/land/land.flow.ts Resolved

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 5 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread examples/land/land.flow.ts Resolved
Comment thread examples/land/land.flow.ts Resolved
khaliqgant and others added 2 commits November 2, 2026 23:11
…nded

Greptile on #695: if GitHub accepts the atomic push but the connection drops
before git hears back, the push exits nonzero, the land ref is already
deleted, and the run was saved cancelled (superseded) for work that landed.
On a failed push F now fetches the base and, if this run's Land-Run trailer
is on it, records the landed commit before considering supersession.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…sion

cubic on #695:
- A replayed F checks its own Land-Run trailer on the base whenever the land
  ref is not at the pinned head (gone, or recreated by a newer submission),
  not only when it is gone.
- The fence deletes the land ref, so the auto write grant must allow deleting
  land/* branches; a dry-run push cannot prove branch rules, so this is
  documented in the README and the evidence README.
- The evidence script captures the server's ref updates on every trial and
  shell-quotes the paths it writes into the hook.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@kjgbot kjgbot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The atomic deletion addresses my original no-op-ref finding; real Git race probe confirmed rejection with main unchanged. The added replay reconciliation has a fresh-hosted-checkout integration gap noted inline. This review does not modify the owned source or train.

Comment thread examples/land/land.flow.ts Resolved

@kjgbot kjgbot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed exact head bd2e03b. The E/F-only write probe matches the staged grants, and the real atomic deletion addresses my original no-op-ref race. Accepted the post-push fresh-retry reporting gap as tracked P2 #697; that recovery behavior remains unfinished and is not part of this signoff. Cloud cancellation still has a separate finding on cloud#5944; this approval does not approve its execution-stop/slot-release path or production rollout.

@khaliqgant
khaliqgant merged commit ec52d08 into main Nov 3, 2026
4 checks passed
@khaliqgant
khaliqgant deleted the fix/land-preflight-write-stages branch November 3, 2026 07:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants